<?php
class RandomShopVo extends SzAbstractMySqlVo
{

    private $userId;
    private $typeId;
    private $itemIdList;
    private $lastTime;

    /**
     * Initialize RandomShopVo.
     *
     * @param $userId
     * @param $typeId
     * @param $itemIdList
     * @param $lastTime
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return RandomShopVo
     */
    public function __construct($userId, $typeId, $itemIdList, $lastTime, $isInsert = false) {
        $this->userId = $userId;
        $this->typeId = $typeId;
        $this->itemIdList = json_decode($itemIdList, true);
        $this->lastTime = $lastTime;

        $this->isInsert = $isInsert;
        $this->voClassName = 'RandomShopVo';
        $this->ormName = 'RandomShop';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'typeId' => $this->getTypeId(),
            'itemIdList' => ($needEncode) ? $this->getItemIdList() : $this->getRawItemIdList(),
            'lastTime' => $this->getLastTime(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'typeId' => $this->getTypeId(),
            'itemIdList' => ($needEncode) ? $this->getItemIdList() : $this->getRawItemIdList(),
            'lastTime' => $this->getLastTime(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getTypeId(),
            $this->getItemIdList(),
            $this->getLastTime(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getTypeId()
    {
        return $this->typeId;
    }

    public function setTypeId($val)
    {
        $this->saveColumnStatus(1, $this->typeId);
        $this->typeId = $val;
    }

    public function getItemIdList()
    {
        return json_encode($this->itemIdList);
    }

    public function getRawItemIdList()
    {
        return $this->itemIdList;
    }

    public function setItemIdList($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 21840) {
            SzLogger::get()->error('[RandomShopVo] The length of column itemIdList exceed the limit, length / limit: ' . $encodedLength . ' / 21840');
            throw new SzException(10522, array('RandomShopVo', '21840', $encodedLength));
        } else if ($encodedLength > 19656) {
            SzLogger::get()->warn('[RandomShopVo] The length of column itemIdList exceed the warning level, length / limit: ' . $encodedLength . ' / 21840');
        }
        $this->saveColumnStatus(2, $this->itemIdList);
        $this->itemIdList = $val;
    }

    public function getLastTime()
    {
        return $this->lastTime;
    }

    public function setLastTime($val)
    {
        $this->saveColumnStatus(3, $this->lastTime);
        $this->lastTime = $val;
    }

}